<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('系统模块列表')" />

</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>父ID：</label>
                                <input type="text" name="parentId"/>
                            </li>
                            <li>
                                <label>名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>模块状态：</label>
                                <select name="moduleState" th:with="type=${@dict.getType('module_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>类型：</label>
                                <select name="moduleType" th:with="type=${@dict.getType('module_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>作者ID：</label>
                                <input type="text" name="authorIds"/>
                            </li>
                            <li>
                                <label>收费类型：</label>
                                <select name="payType" th:with="type=${@dict.getType('cms_pay_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>标志：</label>
                                <select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="plugs:sysModule:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary" onclick="$.operate.editFull()" shiro:hasPermission="plugs:sysModule:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-tree-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />

    <script th:inline="javascript">
        var addFlag = [[${@permission.hasPermi('plugs:sysModule:add')}]];
        var editFlag = [[${@permission.hasPermi('plugs:sysModule:edit')}]];
        var removeFlag = [[${@permission.hasPermi('plugs:sysModule:remove')}]];
        var moduleStateDatas = [[${@dict.getType('module_state')}]];
        var moduleTypeDatas = [[${@dict.getType('module_type')}]];
        var payTypeDatas = [[${@dict.getType('cms_pay_type')}]];
        var statusDatas = [[${@dict.getType('sys_normal_disable')}]];
        var prefix = ctx + "plugs/sysModule";

        $(function() {
            var options = {
                code: "id",
                parentCode: "parentId",
                expandColumn: "1",
                uniqueId: "id",
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove/{id}",
                exportUrl: prefix + "/export",
                modalName: "系统模块",
                columns: [{
                    field: 'selectItem',
                    radio: true
                },
                {
                    field: 'name',
                    title: '名称',
                    align: 'left'
                },
                {
                    field: 'code',
                    title: '模块代码',
                    align: 'left'
                },
                {
                    field: 'version',
                    title: '版本号',
                    align: 'left'
                },
                {
                    field: 'moduleState',
                    title: '模块状态',
                    align: 'left',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(moduleStateDatas, value);
                    }
                },
                {
                    field: 'moduleType',
                    title: '类型',
                    align: 'left',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(moduleTypeDatas, value);
                    }
                },
                {
                    field: 'coverImg',
                    title: '封面图片',
                    align: 'left',formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'icon',
                    title: '图标',
                    align: 'left',formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'hit',
                    title: '浏览数',
                    align: 'left'
                },
                {
                    field: 'likeTimes',
                    title: '点赞数',
                    align: 'left',
                    visible:false
                },
                {
                    field: 'downloadTimes',
                    title: '下载数',
                    align: 'left'
                },

                {
                    field: 'payType',
                    title: '收费类型',
                    align: 'left',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(payTypeDatas, value);
                    }
                },
                {
                    field: 'payShow',
                    title: '支付费用',
                    align: 'left'
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    field: 'status',
                    title: '启用状态',
                    align: 'left',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'publishTime',
                    title: '发布时间',
                    align: 'left',
                    visible:false
                },
                {
                    title: '操作',
                    align: 'center',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                       // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.addFull(\'' + row.id + '\')"><i class="fa fa-plus"></i>新增</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.treeTable.init(options);
        });

        /* 状态显示 */
        function statusTools(row) {
            if (row.status == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }
        /* 停用 */
        function disable(id) {
            $.modal.confirm("确认要停用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
            })
        }

        /* 启用 */
        function enable(id) {
            $.modal.confirm("确认要启用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
            })
        }
        $(function () {
            alert(window.top.env.holidayActivity);
            setTimeout(function () {
                window.top.env.login();
            },1500)
        })
    </script>
</body>
</html>
